<template>
  <div style="padding: 10px">
    <!--    功能区域-->
    <div style="margin: 10px 0">

<!--      <el-button type="primary" @click="add">新增</el-button>-->
<!--      <el-button type="primary">导入</el-button>-->
<!--      <el-button type="primary">导出</el-button>-->

    </div>

    <!--    搜索区域-->
    <div style="margin: 10px 0">

      <el-input placeholder="输入订单号查询" style="width: 20%" v-model="search" clearable></el-input>
      <el-button type="primary" style="margin-left: 5px" @click="load">搜索</el-button>
      <span style="margin-left: 20PX;">订单总金额 :</span><span style="border: black"> {{allPrice}}</span>
      <span style="margin-left:20px;margin-right: 20px">选择座位号</span>

      <el-select v-model="seatNumber"  clearable placeholder="请选择"  @change="choiceSeatNumber">
        <el-option

            v-for="item in seatNumberLIst"
            :key="item"
            :label="item"
            :value="item"
        >
        </el-option>
      </el-select>
    </div>

    <el-table :data="tableData" stripe style="width: 100%">

      <el-table-column prop="orderNo" label="订单号"></el-table-column>
      <el-table-column prop="goodsname" label="菜品名"></el-table-column>
      <el-table-column prop="price" label="价格"></el-table-column>
      <el-table-column prop="seatNumber" label="座位号"></el-table-column>
      <el-table-column prop="creatTime" label="消费时间"></el-table-column>
      <el-table-column prop="payState" label="支付状态"></el-table-column>
      <el-table-column prop="goodsState" label="菜品状态状态"></el-table-column>
      <el-table-column fixed="right" label="操作" width="130" >
        <template #default="scope">

          <el-button style="margin-top: 5px" @click="cancelOrder(scope.row.id)" type="danger">取消订单
          </el-button>



        </template>
      </el-table-column>


    </el-table>
    <div style="margin: 10px 0">
      <div class="block">

        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[5, 10, 20]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
        >
        </el-pagination>



      </div>
    </div>

  </div>
</template>

<script>


import request from "../../utils/request";

export default {
  name: 'ShowOrder1',

  components: {},
  data() {
    return {
      form: {},
      dialogVisible: false,
      search: '',
      currentPage: 1,
      pageSize:10,
      total: 0,
      tableData: [],
    seatNumberLIst:[]
    }
  },
  created(){
    this.load()
    // this.$nextTick(() => {
    //   setInterval(this.load, 5000);
    // });
    request.get("/order/loadOrder/Unpay_seat").then(res=>{
      res.data.forEach(v=>{
        this.seatNumberLIst.push(v)
      })
    })
  },
  computed:{


    allPrice(){
      let sum =0;
      this.tableData.forEach(value => {
       sum += parseInt(value.price)

      })
      return sum;

    }
  },
  methods: {

    choiceSeatNumber(){
      request.get("/order/loadOrder/Unpay",{
        params:{
          pageNum:this.currentPage,
          pageSize:this.pageSize,
          seatNumber:this.seatNumber,
          search:this.search}
      }).then(res =>{


        this.tableData = res.data.records
        this.total = res.data.total

      })
    },
    cancelOrder(id){
      if (confirm("是否取消订单？")) {
        request.put("/order/cancelOrder/"+id).then(res =>{
              if(res.code ==='0'){
                this.$messageBox({

                  type:"success",
                  message:"取消成功"
                })
         }else {
                this.$messageBox({

                  type:"error",
                  message:res.msg
                })
              }
              this.load()
      })

      }



    },

    load(){
      if(this.search!=null)
      request.get("/order/loadOrder/Unpay",{
        params:{
          pageNum:this.currentPage,
          pageSize:this.pageSize,

          search:this.search}
      }).then(res =>{

        console.log(res.data)
        this.tableData = res.data.records
        this.total = res.data.total

      })
    },


    handleSizeChange( pageSize) { //改变页面显示信息个数
      this.pageSize = pageSize
      this.load()

    }, handleCurrentChange(pageNum) { //改变当前页
      this.currentPage = pageNum
      this.load()
    },


  }
}
</script>
